import 'package:calendar_date_picker2/calendar_date_picker2.dart';
import 'package:date_format/date_format.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:sptapp/widget/common_widget.dart';

import '../../config/const.dart';

class InverterDetailDialog extends StatefulWidget {
  const InverterDetailDialog({super.key});

  @override
  State<InverterDetailDialog> createState() => _InverterDetailDialogState();
}

class _InverterDetailDialogState extends State<InverterDetailDialog> {

  int statusIndex = 0;
  int waringIndex = 0;
  List<DateTime> time = [];


  @override
  void initState() {
    // TODO: implement initState
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.symmetric(horizontal: 30.w,vertical: 30.w),
      decoration: BoxDecoration(
          color: Colors.white
      ),
      constraints: BoxConstraints(
          maxHeight: 0.7.sh
      ),
      child: SingleChildScrollView(
        child: Column(
          children: [
            Container(
              child: Text('故障告警筛选'),
              alignment: Alignment.centerLeft,
            ),
            SizedBox(height: 30.w,),
            Container(
              child: Column(
                children: [
                  Container(
                    child: Text('故障状态'),
                    alignment: Alignment.centerLeft,
                  ),
                  SizedBox(height: 30.w,),
                  Container(
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        GestureDetector(
                          onTap: (){
                            setState(() {
                              statusIndex = 0;
                            });
                          },
                          child: Container(
                            height: 80.w,
                            width: 180.w,
                            alignment: Alignment.center,
                            decoration: BoxDecoration(
                                color: statusIndex == 0? themeColor: Colors.grey,
                                borderRadius: BorderRadius.circular(90.w)
                            ),
                            child: Text('全部'),
                          ),
                        ),
                        GestureDetector(
                          onTap: (){
                            setState(() {
                              statusIndex = 1;
                            });
                          },
                          child: Container(
                            height: 80.w,
                            width: 180.w,
                            alignment: Alignment.center,
                            decoration: BoxDecoration(
                                color: statusIndex == 1? themeColor: Colors.grey,
                                borderRadius: BorderRadius.circular(90.w)
                            ),
                            child: Text('发生中'),
                          ),
                        ),
                        GestureDetector(
                          onTap: (){
                            setState(() {
                              statusIndex = 2;
                            });
                          },
                          child: Container(
                            height: 80.w,
                            width: 180.w,
                            alignment: Alignment.center,
                            decoration: BoxDecoration(
                                color: statusIndex == 2? themeColor: Colors.grey,
                                borderRadius: BorderRadius.circular(90.w)
                            ),
                            child: Text('已结束'),
                          ),
                        ),
                      ],
                    ),
                  ),
                ],
              ),
            ),
            SizedBox(height: 30.w,),
            Container(
              child: Column(
                children: [
                  Container(
                    child: Text('故障告警'),
                    alignment: Alignment.centerLeft,
                  ),
                  SizedBox(height: 30.w,),
                  Container(
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        GestureDetector(
                          onTap: (){
                            setState(() {
                              waringIndex = 0;
                            });
                          },
                          child: Container(
                            height: 80.w,
                            width: 180.w,
                            alignment: Alignment.center,
                            decoration: BoxDecoration(
                                color: waringIndex == 0? themeColor: Colors.grey,
                                borderRadius: BorderRadius.circular(90.w)
                            ),
                            child: Text('全部'),
                          ),
                        ),
                        GestureDetector(
                          onTap: (){
                            setState(() {
                              waringIndex = 1;
                            });
                          },
                          child: Container(
                            height: 80.w,
                            width: 180.w,
                            alignment: Alignment.center,
                            decoration: BoxDecoration(
                                color: waringIndex == 1? themeColor: Colors.grey,
                                borderRadius: BorderRadius.circular(90.w)
                            ),
                            child: Text('故障'),
                          ),
                        ),
                        GestureDetector(
                          onTap: (){
                            setState(() {
                              waringIndex = 2;
                            });
                          },
                          child: Container(
                            height: 80.w,
                            width: 180.w,
                            alignment: Alignment.center,
                            decoration: BoxDecoration(
                                color: waringIndex == 2? themeColor: Colors.grey,
                                borderRadius: BorderRadius.circular(90.w)
                            ),
                            child: Text('告警'),
                          ),
                        ),
                      ],
                    ),
                  ),
                ],
              ),
            ),
            SizedBox(height: 30.w,),
            Container(
              child: Column(
                children: [
                  Container(
                    child: Text('时间范围'),
                    alignment: Alignment.centerLeft,
                  ),
                  SizedBox(height: 30.w,),
                  GestureDetector(
                    onTap: (){
                      SmartDialog.show(builder: (context) {
                        return Container(
                          decoration: BoxDecoration(
                            color: Colors.white,
                            borderRadius: BorderRadius.circular(20.w)
                          ),
                          padding: EdgeInsets.symmetric(vertical: 30.w,horizontal: 20.w),
                          child: Column(
                            mainAxisSize: MainAxisSize.min,
                            children: [
                              Container(
                                child: Row(
                                  mainAxisAlignment: MainAxisAlignment.end,
                                  children: [
                                    GestureDetector(
                                      onTap: (){
                                        SmartDialog.dismiss();
                                      },
                                      child: Container(
                                        width: 120.w,
                                        height: 80.w,
                                        alignment: Alignment.center,
                                        decoration: BoxDecoration(
                                          color: themeColor,
                                          borderRadius: BorderRadius.circular(20.w)
                                        ),
                                        child: Text('确定'),
                                      ),
                                    )
                                  ],
                                ),
                              ),
                              CalendarDatePicker2(
                                config: CalendarDatePicker2Config(
                                  calendarType: CalendarDatePicker2Type.range,
                                ),
                                value: time,
                                onValueChanged: (dates){
                                  setState(() {
                                    time = dates;
                                  });
                                },
                              )
                            ],
                          ),
                        );
                      },alignment: Alignment.bottomCenter,clickMaskDismiss: true);
                    },
                    child: Container(
                      child: Container(
                        width: 690.w,
                        height: 80.w,
                        alignment: Alignment.center,
                        decoration: BoxDecoration(
                            color: Colors.grey,
                            borderRadius: BorderRadius.circular(80.w)
                        ),
                        child: Text(time.isEmpty || time.length<2?'开始时间-结束时间':'${formatDate(time[0], [yyyy,'.',mm,'.',dd])}-${formatDate(time[1], [yyyy,'.',mm,'.',dd])}'),
                      ),
                    ),
                  ),
                ],
              ),
            ),
            SizedBox(height: 30.w,),
            Container(
              child: Container(
                width: 690.w,
                height: 80.w,
                alignment: Alignment.center,
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    GestureDetector(
                      onTap: (){
                        SmartDialog.dismiss();
                      },
                      child: Container(
                        width: 300.w,
                        height: 80.w,
                        decoration: BoxDecoration(
                            color: Colors.grey,
                            borderRadius: BorderRadius.circular(80.w)
                        ),
                        alignment: Alignment.center,
                        child: Text('重置'),
                      ),
                    ),
                    GestureDetector(
                      onTap: (){
                        SmartDialog.dismiss();
                      },
                      child: Container(
                        width: 300.w,
                        height: 80.w,
                        alignment: Alignment.center,
                        decoration: BoxDecoration(
                            color: themeColor,
                            borderRadius: BorderRadius.circular(80.w)
                        ),
                        child: Text('确定'),
                      ),
                    )
                  ],
                ),
              ),
            ),
            SizedBox(height: ScreenUtil().bottomBarHeight+20.w,)

          ],
        ),
      ),
    );
  }
}
